package com.wcs.exam.dao.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wcs.exam.dao.SysMenuRoleDao;
import com.wcs.exam.dao.impl.mapper.SysMenuRoleMapper;
import com.wcs.exam.dao.impl.mapper.entity.SysMenuRole;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 菜单角色关联表 服务实现类
 *
 * @author wcs
 * @since 2024-07-06
 */
@Repository
public class SysMenuRoleDaoImpl extends ServiceImpl<SysMenuRoleMapper, SysMenuRole> implements SysMenuRoleDao {

    @Override
    public <R> List<R> selectObjs(Wrapper<SysMenuRole> wrapper, Class<R> classType) {
        List<Map<String, Object>> resultMaps = baseMapper.selectMaps(wrapper);
        if (CollectionUtil.isEmpty(resultMaps)) {
            return Collections.emptyList();
        }
        return BeanUtil.copyToList(resultMaps, classType);
    }

    @Override
    public List<SysMenuRole> listByRoleIds(Collection<Long> roleIds) {
        return lambdaQuery().in(SysMenuRole::getRoleId, roleIds).list();
    }

    @Override
    public boolean removeByRoleId(Long roleId) {
        return lambdaUpdate().eq(SysMenuRole::getRoleId, roleId).remove();
    }
}
